package myservlet.control;


import mybean.data.super_manager_Bean;

import java.io.*;
import java.sql.*;
import java.text.MessageFormat;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.WebServlet;

@WebServlet("/Todelete")
public class SuperTodelete extends HttpServlet {
    public void init(ServletConfig config) throws ServletException {
        super.init(config);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        HttpSession session = request.getSession(true);
        super_manager_Bean managerBean = null;
        //管理员用户信息的bean
        try {
            managerBean = (super_manager_Bean) session.getAttribute("superLoginBean");
            if (managerBean == null) {
                managerBean = new super_manager_Bean();  //创建Javabean对象
                session.setAttribute("superLoginBean", managerBean);
            }
        } catch (Exception exp) {
            managerBean = new super_manager_Bean();
            session.setAttribute("superLoginBean", managerBean);
        }


        //判断当前是否是登录状态
        if (managerBean.getUsername().equals("") || managerBean.getPassword().equals("")) {
            fail(request, response, "请您先登录管理员账号再使用管理员功能");
            //没有登录, 不给使用管理员功能
            return;
        }


        RequestDispatcher dispatcher=
                request.getRequestDispatcher("/system_operate/delete_u_s.jsp");//转发
        dispatcher.forward(request,response);

    }



    public void fail(HttpServletRequest request, HttpServletResponse response,
                     String backNews) {
        response.setContentType("text/html;charset=GB2312");
        try {
            PrintWriter out = response.getWriter();
            out.println("<html>");
            out.println("<head><style>body{text-align: center;background: #ea66a6;margin:300px}</style></head>");
            out.println("<body>");
            out.println("<h2>" + backNews + "</h2>");
            out.println("返回");
            out.println("<a href =/Vice_School_ShopWeb_war_exploded/index.jsp>主页</a>");
            out.println("<a href =/Vice_School_ShopWeb_war_exploded/system_operate/super_login.jsp>管理员登录页面</a>");
            out.println("</body></html>");
        } catch (IOException exp) {
        }
    }
}
